package com.mis.pos.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.mis.pos.base.entity.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

/**
 * @description:系统角色
 * @author: yuxiang
 * @create: 2019-12-12 15:40
 **/
@Entity
@Table(name = "sys_role")
public class SysRole extends BaseEntity {

    //角色名
    private String name;
    //角色描述
    private String description;

    //角色 -- 权限 多对多
    @JsonIgnoreProperties(value = {"roles"})
    @ManyToMany
    //inverseJoinColumns逆加入的列
    @JoinTable(name = "SysRolePermission",joinColumns = {@JoinColumn(name = "roleId")}, inverseJoinColumns = {@JoinColumn(name = "permissionId")})
    private List<SysPermission> permissions;

    // 用户 -- 角色关系：多对多
    @JsonIgnoreProperties(value = {"roles"})
    @ManyToMany
    @JoinTable(name = "SysUserRole", joinColumns = {@JoinColumn(name = "roleId")}, inverseJoinColumns = {@JoinColumn(name = "userId")})
    private List<UserEntity> users;// 一个角色对应多个用户

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<SysPermission> getPermissions() {
        return permissions;
    }

    public void setPermissions(List<SysPermission> permissions) {
        this.permissions = permissions;
    }

    public List<UserEntity> getUsers() {
        return users;
    }

    public void setUsers(List<UserEntity> users) {
        this.users = users;
    }
}
